<template>
  <div>
    <el-select
      popper-class="wzd-select"
      size="mini"
      v-model="check_value"
      placeholder="请选择"
      ref="select"
      @blur="blur"
    >
      <el-option :value="check_value">
        <el-tree
          :data="treedata"
          :props="defaultProps"
          @node-click="handleNodeClick"
        ></el-tree>
      </el-option>
    </el-select>
  </div>
</template>

<script>
export default {
  name: "TreeSelect",
  data() {
    return {
      input: "",
      options: [
        {
          value: "选项1",
          label: "黄金糕",
        },
        {
          value: "选项2",
          label: "双皮奶",
        },
        {
          value: "选项3",
          label: "蚵仔煎",
        },
        {
          value: "选项4",
          label: "龙须面",
        },
        {
          value: "选项5",
          label: "北京烤鸭",
        },
      ],
      check_value: "",
      treedata: [
        {
          label: "一级 1",
          children: [
            {
              label: "二级 1-1",
              children: [
                {
                  label: "三级 1-1-1",
                },
              ],
            },
          ],
        },
        {
          label: "一级 2",
          children: [
            {
              label: "二级 2-1",
              children: [
                {
                  label: "三级 2-1-1",
                },
              ],
            },
            {
              label: "二级 2-2",
              children: [
                {
                  label: "三级 2-2-1111111111111",
                },
              ],
            },
          ],
        },
        {
          label: "一级 3",
          children: [
            {
              label: "二级 3-1",
              children: [
                {
                  label: "三级 3-1-1",
                },
              ],
            },
            {
              label: "二级 3-2",
              children: [
                {
                  label: "三级 3-2-1",
                },
              ],
            },
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  methods: {
    handleNodeClick(data) {
      this.check_value = data.label;
    },
    focus(value) {
      console.log("asfd", value);
    },
    blur() {
      this.$refs.select.focus();
    },
  },
};
</script>

<style lang="less" scoped>
// 隐藏el-select的下拉面板
// ::v-deep .el-tree {
//   min-height: 200px;
// }
</style>
<style lang="less">
.wzd-select {
  .el-select-dropdown__item.hover {
    background-color: transparent;
  }
  // 隐藏el-select的下拉面板，并设置最低高度
  .el-select-dropdown__item {
    background-color: transparent;
    height: auto;
    min-height: 200px;
    cursor: auto;
  }
  // 设置el-select面板选中后的样式不改变
  .el-select-dropdown__item.selected {
    color: #606266;
    font-weight: 400;
  }
}
</style>
